{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fabfbbcb",
   "metadata": {},
   "source": [
    "### A. 试题A：完美车牌 5’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a4372ce",
   "metadata": {},
   "source": [
    "有一些数字可以颠倒过来看，例如0、1、8颠倒过来还是本身，6颠倒过来是9，9颠倒过来看还是6，其他数字颠倒过来不构成数字。\n",
    "\n",
    "类似的，一些多位数也可以颠倒过来看，比如106颠倒过来是901\n",
    "\n",
    "假设某个城市的车牌只由6位数字组成,每一位都可以取0到9。请问这个城市最多有多少个车牌180°180°倒过来恰好还是原来的车牌?\n",
    "\n",
    "例如：车牌号：886988,倒过来还是886988\n",
    "\n",
    "【答案提交】\n",
    "\n",
    "这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个数字，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08cd1eb0",
   "metadata": {},
   "outputs": [],
   "source": [
    "ans = 0\n",
    "for i in range(1, 1000000):\n",
    "    \n",
    "    i = str(i).zfill(6) # 补充前导0\n",
    "    \n",
    "    if '2' in str(i) or '3' in str(i) or '4' in str(i) or '5' in str(i) or '7' in str(i):\n",
    "        continue\n",
    "    \n",
    "    else:\n",
    "        s = str(i)\n",
    "        \n",
    "        s1 = ''\n",
    "        for i in range(6):\n",
    "            if s[5-i] == '6':\n",
    "                s1 += '9'\n",
    "            elif s[5-i] == '9':\n",
    "                s1 += '6'\n",
    "            else:\n",
    "                s1 += s[5-i]\n",
    "\n",
    "        if s == s1:\n",
    "            ans += 1\n",
    "            print(s)\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70c34278",
   "metadata": {},
   "source": [
    "### B. 试题B：完美日期 5’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2953db6e",
   "metadata": {},
   "source": [
    "不知天上宫阙，今夕是何年。\n",
    "\n",
    "对于完美日期yyyy/mm/dd，wlxsq的定义是:\n",
    "\n",
    "年月日中均没有出现数字4，\n",
    "年月日的数位之和是8的倍数\n",
    "例如：2020/02/02 就是一个完美日期，没有出现数字4，且数位之和是8的倍数。\n",
    "\n",
    "wlxsq想知道从2020/02/02开始，第88个完美日期是哪个？\n",
    "\n",
    "【答案提交】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ec0f355",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime, timedelta\n",
    "\n",
    "now = datetime.strptime('2020/02/02', '%Y/%m/%d')\n",
    "\n",
    "num = 0\n",
    "\n",
    "while num != 88:\n",
    "    \n",
    "    now = now + timedelta(1)\n",
    "    \n",
    "    day_string = datetime.strftime(now, '%Y%m%d')\n",
    "    \n",
    "    if '4' in day_string:\n",
    "        continue\n",
    "    \n",
    "    day_string = [int(i) for i in day_string]\n",
    "    \n",
    "    \n",
    "    if sum(day_string) == 8:\n",
    "        num = num + 1\n",
    "        \n",
    "print(now)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f2f0504",
   "metadata": {},
   "source": [
    "### C. 试题C：天机锁10’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2f71d79",
   "metadata": {},
   "source": [
    "描述\n",
    "【问题描述】\n",
    "\n",
    "天机锁，锁天机\n",
    "\n",
    "wlxsq在机缘巧合的情况下就获得一把天机锁。wlxsq迫不及待的想打开这把锁。该锁的密码是由八个数字构成的,每个数字都是[0,9]中的一个~\n",
    "\n",
    "锁上面写道：\n",
    "\n",
    "水(数字9)火(数字4)相生相克,同现同隐(要么都出现，要么都不出现),数量一致(且出现则数量得一样多)。\n",
    "\n",
    "土(数字2)乃大地，为伊始(数字2一定出现)。\n",
    "\n",
    "世间万物，不过五二(八个数字之和不超过52)。\n",
    "\n",
    "此乃天机，一日一次之\n",
    "\n",
    "由于天机锁一天只能试一次，wlxsq想知道，总共有多少种方案\n",
    "50035415"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f0811f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "results = list()\n",
    "\n",
    "nums = list()\n",
    "\n",
    "for i in range(100000000):\n",
    "    \n",
    "    nums = str(i).zfill(8)\n",
    "    \n",
    "                                    \n",
    "    if '2' in nums:\n",
    "        if '4' in nums and '9' in nums:\n",
    "            if nums.count('4') == nums.count('9'):\n",
    "                if sum([int(_) for _ in list(nums)]) <= 52:\n",
    "                    results.append(nums)\n",
    "\n",
    "        else:\n",
    "            if sum([int(_) for _ in list(nums)]) <= 52:\n",
    "                    results.append(nums)\n",
    "                                         \n",
    "        \n",
    "        \n",
    "print(len(results))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c75ed81a",
   "metadata": {},
   "source": [
    "### D. 试题D：完美运算 10‘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bef7777e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(n):\n",
    "    x = 3\n",
    "    #n为待转换的十进制数，x为机制，取值为2-16\n",
    "    a=[0,1,2,3,4,5,6,7,8,9,'A','b','C','D','E','F']\n",
    "    b=[]\n",
    "    while True:\n",
    "        s=n // x  # 商\n",
    "        y=n % x  # 余数\n",
    "        b=b+[y]\n",
    "        if s==0:\n",
    "            break\n",
    "        n=s\n",
    "    b.reverse()\n",
    "    ans = ''\n",
    "    for i in b:\n",
    "        ans += str(a[i])\n",
    "    return ans\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    ans = 0\n",
    "    ans2 = 0\n",
    "    for i in range(1, 2021):\n",
    "        for j in range(1, 2021):\n",
    "            a1 = f(i).count('1')\n",
    "            a2 = f(i).count('2')\n",
    "            b1 = f(j).count('1')\n",
    "            b2 = f(j).count('2')\n",
    "            if abs(int(a1)-int(a2)) == abs(int(b1)-int(b2)):\n",
    "                ans += 1\n",
    "            if i == j:\n",
    "                ans2 += 1\n",
    "    print(ans)\n",
    "    print(ans2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45fd114e",
   "metadata": {},
   "source": [
    "### F. 试题F：JM斗牛 17’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7354bbba",
   "metadata": {},
   "source": [
    "描述\n",
    "JM打完麻将，觉得太简单了，所以决定去斗牛，挑战一下高难度。\n",
    "\n",
    "一副牌共54张牌，即采用牌大王(1张),小王(1张),K，Q，J，10，9，8，7，6，5，4，3，2，A。除了大小王，其余牌型均为4张。故4*13+2=54张\n",
    "\n",
    "斗牛则是每人5张牌，计算5张牌的构成的点数，然后比较点数大小。\n",
    "\n",
    "关于点数计算：\n",
    "\n",
    "大王(S)，小王(S)，K，Q，J都当成是10点，A当成是1点，其余牌都当其本身的点数。 大王，小王均用大写字母S表示\n",
    "每位玩家5张牌，玩家用手上任意的3张牌组合（且只能用3张牌组成10的倍数），使其点数之和为10的倍数，这样就称之为“牛”。\n",
    "然后将剩余的2张牌点数之和取个位数，如这2张牌之和也为10的倍数，则组成“牛牛”牌型。如这2张牌之和不为10的整数倍，则去掉十位数之后个位数为几，则成为“牛几”牌型。\n",
    "如任意三张牌组合的点数之和都不能成为10的倍数，则称之为“无牛”牌型。\n",
    "例如：\n",
    "\n",
    "牛牛牌型:选取的3张牌之和为10的整数倍,余下2张牌之和也为10的整数倍。例：A,9,10,J,Q.选取(A,9,J)和为10的整数倍,(10,Q构成)牛牛\n",
    "\n",
    "牛九牌型:选取的3张牌之和为10的整数倍,余下2张牌之和的个位数为9。例：A,9,10,J,9。\n",
    "\n",
    "牛八牌型:选取的3张牌之和为10的整数倍,余下2张牌之和的个位数为8。例：A,9,10,J,8。\n",
    "\n",
    "牛七牌型:选取的3张牌之和为10的整数倍,余下2张牌之和的个位数为7。例:A,9,10,J,7。选取(A,9,J)和为10的整数倍，(10,7构成)牛七\n",
    "\n",
    "无牛牌型: 任意选取的3张牌之和均不可能为10的整数倍例:A,9,8,9,7。\n",
    "\n",
    "JM会打麻将，但是不怎么会斗牛，想请你帮忙编写程序帮忙计算一下，JM 拿到的牌是什么牌型。\n",
    "样例\n",
    "\n",
    "输入\n",
    "A 2 3 5 S\n",
    "输出\n",
    "1\n",
    "输入\n",
    "S S A 8 8\n",
    "输出\n",
    "so sad!\n",
    "输入\n",
    "S S J Q K\n",
    "输出\n",
    "so cool!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e923923f",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "cards = list(map(str, input().split()))\n",
    "\n",
    "cards = [10 if card in ['K', 'Q', 'J', 'S'] else card for card in cards]\n",
    "\n",
    "cards = [1 if card == 'A' else int(card) for card in cards]\n",
    "\n",
    "if cards.count(10) == 5:\n",
    "    print('so cool!')\n",
    "    \n",
    "elif cards.count(10) == 4:\n",
    "    result = sum(cards) - 40\n",
    "    \n",
    "    if result == 10:\n",
    "        print('so cool!')\n",
    "    else:\n",
    "        print(result if result < 10 else result - 10)\n",
    "\n",
    "elif cards.count(10) == 3:\n",
    "    result = sum(cards) - 30\n",
    "    \n",
    "    if result == 10:\n",
    "        print('so cool!')\n",
    "    else:\n",
    "        print(result if result < 10 else result - 10)\n",
    "        \n",
    "elif cards.count(10) == 2:\n",
    "    \n",
    "    if sum([card if card != 10 else 0 for card in cards]) == 10:\n",
    "        print('so cool!')\n",
    "        \n",
    "    else:\n",
    "        print('so sad!')\n",
    "\n",
    "elif cards.count(10) == 1:\n",
    "    \n",
    "    ans = sum(cards) % 10\n",
    "    \n",
    "    if ans in cards:\n",
    "        print(ans)\n",
    "        \n",
    "    else:\n",
    "        print('so sad!')\n",
    "        \n",
    "else:\n",
    "    ans = sum(cards) % 10\n",
    "    \n",
    "    if ans in cards:\n",
    "        print(ans)\n",
    "        \n",
    "    else:\n",
    "        print('so sad!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad77aef6",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "cards = list(map(str, input().split()))\n",
    "\n",
    "cards = [10 if card in ['K', 'Q', 'J', 'S'] else card for card in cards]\n",
    "\n",
    "cards = [1 if card == 'A' else int(card) for card in cards]\n",
    "\n",
    "result = sum(cards)\n",
    "\n",
    "if result > 10:\n",
    "    \n",
    "    ans = result % 10\n",
    "    \n",
    "    if ans == 0:\n",
    "        print('so cool!')\n",
    "        \n",
    "    elif ans in cards:\n",
    "        print(ans)\n",
    "        \n",
    "    else:\n",
    "        print('so sad!')\n",
    "        \n",
    "else:\n",
    "    print('so sad!')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37eca1ab",
   "metadata": {},
   "source": [
    "### H. 试题H：宝剑锋从磨砺出 20’"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e12d2d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "n,k = map(int, input().split())\n",
    "ans = 0\n",
    "list1 = []\n",
    "list2 = []\n",
    "for i in range(n):\n",
    "    a,b = map(int, input().split())\n",
    "    list1.append(a)\n",
    "    list2.append(b)\n",
    "list1 = sorted(list1)\n",
    "list2 = sorted(list2)\n",
    "while list2 and list2[-1] > list1[-1] and k > 0:\n",
    "    k -= list2[-1]\n",
    "    list2.pop()\n",
    "    ans += 1\n",
    "if k > 0:\n",
    "    ans += k // list1[-1] + 1\n",
    "print(ans)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
